﻿CREATE PROCEDURE [dbo].[MemberInsert]
	@userName				VARCHAR(8),
	@password				VARCHAR(8),
	@roleId					INT,
	@firstName				VARCHAR(50),
	@lastName				VARCHAR(50),		
	@gender					CHAR(1),
	@dateOfBirth			DATE,
	@passportNo				VARCHAR(20),
	@address1				VARCHAR(50),
	@address2				VARCHAR(50),
	@address3				VARCHAR(50),
	@city					VARCHAR(10),
	@postalCode				VARCHAR(10),
	@country				VARCHAR(50),	
	@passportExpiryDate		DATE,
	@memberPoints			INT
AS
BEGIN
	DECLARE @customerId INT

	INSERT INTO [dbo].[Customers] ([UserName], [Password], [RoleId], [FirstName], [LastName], [Gender], [DateOfBirth])
    VALUES (@userName, @password, @roleId, @firstName, @lastName, @gender, @dateOfBirth);

    SET @customerId = CAST(IDENT_CURRENT('Customers') AS INT);

	INSERT INTO [dbo].[Members] ([CustomerId], [PassportNo], [Address1], [Address2], [Address3], [City], [PostalCode], [Country], [PassportExpiryDate], [MemberPoints])
	VALUES (@customerId, @passportNo, @address1, @address2, @address3, @city, @postalCode, @country, @passportExpiryDate, @memberPoints);

	SELECT @customerId AS 'CustomerId', CAST(IDENT_CURRENT('Members') AS INT) AS 'MemberId'
END